<template>
  <view>
    <view v-if="isSinglePage" class="single">
      <view class="startAssessment" @click="handleStartAssessment">
        开始测评
      </view>
    </view>
    <template v-else>
      <!-- 已支付页面  -->
      <!-- v-if="status == 2 && isPayed" -->
      <JuniorCareerAssessResult  :resultInfo="resultData" :fromWhere="fromWhere"
        :toBook="toBook" :scrollRes="scrollRes" :personId="personId" />

      <!-- 未支付页面
      <CareerAssessLockResult v-if="status == 2 && !isPayed" :resultInfo="resultData" :scrollRes="scrollRes"
        @refreshCareerAssessData="handleRefresh" />

      <CareerAssessBeginUi v-if="status == 0 || status == 1" /> -->
    </template>
  </view>
</template>

<script>
import CareerAssessBeginUi from "../components/CareerAssessBeginUi.vue";
import CareerAssessLockResult from "../components/CareerAssessLockResult";
import CareerAssessUnLockStatusResult from "../components/CareerAssessUnLockStatusResult";
import JuniorCareerAssessResult from "../components/JuniorCareerAssessResult";

import { showDelayToastTip } from "@/utils/handle";
import { getCareerAssessmentData } from "@/api/modules/activity";
import { addBuryingPoint } from "@/api/modules/career";
// import ShareMixin from "@/mixins/share";

/**
 * 1.开始测评 pagesSub/career/activity/vocationalAssessment  fromWhere=junior
 * 2.答题 pagesSub/career/activity/vocationalAssessmentAnswer fromWhere=junior&toBook=
 * 2.测评结果 pagesSub/career/activity/JuniorCareerAssessResult  
 * 4.pagesSub/career/activity/JuniorCareerConsultantBuy fromWhere=junior
 * 
 */

export default {
  // mixins: [ShareMixin],
  components: {
    CareerAssessBeginUi,
    CareerAssessLockResult,
    CareerAssessUnLockStatusResult,
    JuniorCareerAssessResult
  },

  data() {
    return {
      // 0-初始状态 1-请求中 2-请求成功
      status: 0,
      scrollRes: {},
      personId: uni.getStorageSync("person-id").slice(2) || undefined,
      //personId: "24192616",
      //  personId: "1",
      isPayed: false,
      resultData: {},
      sharePath: "/pagesSub/career/activity/vocationalAssessment", // 分享自定义路径
      shareTitle: "职业测评",
      shareQuery: "isFromResult=1",
      imageUrl:
        "https://img3.job1001.com/ypMp/elan/images/career/vocationalAssessmentQuestion/share_cover.jpg",
      isSinglePage: false,
      fromWhere: "",
      toBook: "", // 滚动职业宝典的标识
      buryingPointId: "",
      cardType: "",
    };
  },
  watch: {
    // recordId: {
    //   handler(val) {},
    //   deep: true, // 深度监听
    //   immediate: false, // 初始化的时候立刻执行一次
    // },
  },
  onShow() {
    this.buryingPointId = "";
    //  埋点统计访问次数
    this.addBuryingPointFn(20063, "", "", "", "");

    // 埋点统计时长
    this.addBuryingPointFn(20064, "60", "", "", "");
    console.log("-------start_career_assess_result_click------->");
    wx.reportEvent("start_career_assess_result_click", {}); //职业测评-开始测评—测评结果
  },
  onHide() {
    console.log("这里进入了onHide周期");
    this.addBuryingPointFn(20064, "60", "", "", "");
  },
  onUnload() {
    console.log("这里进入了onUnload周期");
    this.addBuryingPointFn(20064, "60", "", "", "");
  },
  onLoad(opt) {
    this.fromWhere = opt.fromWhere || "";
    this.toBook = opt.toBook || "";
    //从职途进来直接观看别人的
    this.personId = opt.personId || uni.getStorageSync("person-id").slice(2);
    let enterOptions = uni.getEnterOptionsSync();
    if (enterOptions.scene == 1154) {
      this.isSinglePage = true;
    }
    if (opt.isFromResult == 1) {
      uni.redirectTo({
        url: `/pagesSub/career/activity/vocationalAssessment?fromWhere=${this.fromWhere}`,
      });
    } else if (opt.fromWhere == "careerPath") {
      this.reqGetCareerAssessmentData();
    } else {
      this.personId && this.reqGetCareerAssessmentData();
    }
    //this.recordId = opt.diagnoseRecordId;
  },

  onPageScroll(res) {
    this.scrollRes = res;
  },

  methods: {
    //普通的埋点+事件停留埋点
    async addBuryingPointFn(
      etId,
      statType,
      jumpPersonId,
      jumpSource,
      sourceType
    ) {
      const params = {
        etId: etId,
        id: this.buryingPointId ? this.buryingPointId : "", //后台要求不能传空，未登录也要统计
        personId: uni.getStorageSync("person-id").slice(2) || "0",
        cardType: this.cardType
          ? this.cardType
          : uni.getStorageSync("cardType") || this.cardType,
        consultantId: uni.getStorageSync("sellId")
          ? uni.getStorageSync("sellId")
          : "",
        originType: this.originFrom == "shareLink" ? 10 : 20,
        statType: statType ? statType : "10",
        jumpPersonId: jumpPersonId,
        jumpSource: jumpSource,
        sourceType: sourceType,
      };
      const res = await addBuryingPoint(params);
      if (res.code == 200) {
        if (res.data.id) {
          if (etId == 20064) this.buryingPointId = res.data.id;
        }
      }
    },
    handleStartAssessment() {
      uni.showToast({
        title: "请前往小程序使用完整服务",
        icon: "none",
      });
    },
    handleRefresh() {
      this.reqGetCareerAssessmentData();
    },

    // 获取职业测评结果
    reqGetCareerAssessmentData() {
      this.status = 1;
      uni.showLoading();
      let param = {
        personId: this.personId,
        assessmentType:"1"
      };
      getCareerAssessmentData(param).then((res) => {
        uni.hideLoading();
        if (res.code == 200) {
          this.status = 2;
          this.resultData = res.data;
          this.isPayed = res.data.payStatus == 1;
        } else {
          this.status = 0;
          showDelayToastTip(res.status_desc, 50);
        }
      });
    },
  },
};
</script>
<style lang="scss" scoped>
.single {
  width: 100%;
  height: 100vh;
  background-image: url($img-base + "career/vocationalAssessmentQuestion/big_cover.png");
  background-size: 100% 100%;

  .startAssessment {
    position: absolute;
    left: 50%;
    bottom: 55px;
    width: 80%;
    height: 94rpx;
    transform: translateX(-50%);
    color: #ffffff;
    text-align: center;
    background: #28cc75;
    border-radius: 8px;
    line-height: 94rpx;
    letter-spacing: 10rpx;
    font-size: 38rpx;
    font-weight: 500;
  }
}
</style>
